package uc.org.jkas.app.admin;
import java.util.HashMap;
import uc.org.jkas.model.AdminlogsM;
public class BackBase extends ScBackBase
{  HashMap<String,String> user=null;
   AdminlogsM asm=new AdminlogsM();
   HashMap<String,Object> logs=new HashMap<String,Object>();
	@SuppressWarnings("unchecked")
    public final String start(boolean auth)
	{ String res="";
	 super.start(auth);
	  try
	  {user=(HashMap<String,String>)session("user");
	  }
	  catch (Exception te)
	  {
	  }

	  if(user==null || user.isEmpty())
		  { res="{islogin:0,msg:\""+L("loginfirst")+"\"}";
			redirect(url("/admin/login"));
		  }

	  return res;
	}

	public boolean init()
	{boolean res=true;
		super.init();
		String nochecks="index_index|index_welcome|passport_reset";
	    String ca=strc(this.getApp(),"_",this.getAct()).toLowerCase();
	    String privs=user.get("privis");
		  
	      assign("user",user);
		  if(privs.equals("*")==false && nochecks.contains(ca)==false && privs.contains(ca)==false)
		  {   echo(L("nopermission"));
			  res=false;
		  }
		  else
		  {logs.put("uid",user.get("uid"));
		   logs.put("log_time",time());
		   logs.put("url",getRequestUri());
		   logs.put("ip",ip2int(clientIp()));
		   logs.put("is_post",IS_POST()?1:0);
		   asm.log(logs);
		  }
	 return res;
	}


}